var _param = {
    init: function () {

    },
    deedList: null,
    page: {
        pageNo: 1,
        pageSize: 9
    }
};
var _deed = {
    init: function () {
        this.operation.init();
        this.getPage();
    },
    operation: {
        init: function () {
            this.add();
            this.edit();
            this.exportDo();
        },
        add: function () {
            $("#add").click(function () {
                layer.confirm("确定新建一次采购？", function () {
                    $.post(baseURL + "deed/add.do", null, function (data) {
                        _Base.result(data, function () {
                            var id = data.result.id;
                            window.location.href = baseURL + "web/goodEntry/" + id;
                        });
                    });

                });
            });
        },
        edit: function () {
           $("body").on('click','.change',function(){
               var id=$(this).parents(".item").attr("data-id");
               window.location.href = baseURL + "web/goodEntry/" + id;
           });
        },
        exportDo: function () {
            $("body").on('click','.export',function(){
                var deedId=$(this).parents(".item").attr("data-id");
                var param={
                    deedId:deedId
                };
                layer.waiting("正在生成中");
                $.post(baseURL+"purchase/export",param,function(data){
                    console.dir(data);
                    _Base.result(data,function(){
                        layer.closeAll();
                        window.location.href=baseURL+data.result;
                    });
                });
            });
        }
    },
    workItem: function (item) {
        item.createTimex=new Date(item.createTime).format("yyyy-MM-dd HH:mm:ss");
        return item;
    },
    getPage: function () {
        var param = {
            pageNo: _param.page.pageNo,
            pageSize: _param.page.pageSize
        };
        $.post(baseURL + "deed/findPage.do", param, function (data) {
            console.dir(data);
            var list = data.entities;
            if (!list || list.length < 1) {
                return;
            }
            var html = _tpl($("#deed_list_tpl").html(), {data: list});
            $("#deed_list_box").html(html);
            laypage({
                cont: 'page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
                pages: data.pageCount, //通过后台拿到的总页数
                curr: data.pageNo, //初始化当前页
                jump: function (e, first) { //触发分页后的回调
                    if (!first) {
                        _param.page.pageNo = e.curr;
                        _deed.getPage();
                    }
                }
            });
        });
    }
};
$(function () {
    _param.init();
    _deed.init();
});

